<?php

class TeachingPeer extends BaseTeachingPeer
{
	static public $choices = array(
			null => 'All',
			1 => 'Active',
			0 => 'not Active',
			);

	static public function getTeachingStatusChoices()
	{
		return self::$choices;
	}
	
	//get teacher id with teacher account
	public static function getTeacherByAccount( $teacherAccount )
	{
		$teacherid = 0;
		$list = DbFinder::from('teacher a')
		->where('a.teacherAccountName', $teacherAccount)
		->findOne()
		;
		if( $list )
			$teacherid = $list->getId();
		return teacherid;
	}
	//get class id in teacher
	public static function getClassIdListByTeacher( $teacherId )
	{
		$list = DbFinder::from('Teaching a')
		->where('a.teacherId', $teacherId)
		->where('a.teachingStatus', 1)
		->orderBy('a.teacherId', 'Asc')
		->find()
		;
		$listid = array();		
		if( $list )
		{
			foreach($list as $row)
			{
				$listid[] = $row->getClassId();
			}
		}
		else
			$listid[0] = 0;//default
		return $listid;
	}
	// get pager class 
	public static function getClassWithTeacher( $teacherId, $lang_current, $start=1, $limit = 10 )
	{
		$listClassId = TeachingPeer::getClassIdListByTeacher( $teacherId );
			return DbFinder::from('Classes a')
			->with('I18n')
			->where('a.clsStatus',1)
			->where('a.id','in', $listClassId)
			->orderBy('a.id', 'Asc')
			//->useCache(sfConfig::get('sf_cache'), 200)
			->paginate($start, $limit);
	}
	
}
